package com.jmye.coding.logback.config;

import ch.qos.logback.classic.pattern.ClassicConverter;
import ch.qos.logback.classic.spi.ILoggingEvent;

/**
 * @description:
 * @author: jmye
 * @date: 2025/7/6 16:34
 **/

public class LogContextConverter extends ClassicConverter {
    @Override
    public String convert(ILoggingEvent event) {
        String mainBatchId = LogContext.get("mainBatchId");
        String childBatchId = LogContext.get("childBatchId");

        // 处理空值情况
        mainBatchId = (mainBatchId != null) ? mainBatchId : "";
        childBatchId = (childBatchId != null) ? childBatchId : "";

        return mainBatchId + " | " + childBatchId;
    }
}
